package com.qf.openapi.web.master.servlet;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/hutoolCap")
public class HutoolCapcharServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //HuTool定义图形验证码的长和宽,验证码的位数，干扰线的条数
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(100, 50, 4, 5);
        //将验证码放入session
        req.getSession().setAttribute("captcha", captcha.getCode());
        captcha.write(resp.getOutputStream());
    }
}
